package com.practice.java8.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class StreamMain {

	public static void main(String[] args) {

		List<String> stringCollection = new ArrayList<String>();
		stringCollection.add("ddd2");
		stringCollection.add("aaa2");
		stringCollection.add("bbb1");
		stringCollection.add("aaa1");
		stringCollection.add("bbb3");
		stringCollection.add("ccc");
		stringCollection.add("bbb2");
		stringCollection.add("ddd1");

		stringCollection.stream().filter(str -> str.startsWith("a"))
				.forEach(System.out::println);

		stringCollection.stream().map(String::toUpperCase)
				.forEach(System.out::println);
		stringCollection.stream().map(str -> str.toUpperCase())
				.forEach(System.out::println);

		boolean anyStartsWithA = stringCollection.stream().anyMatch(
				str -> str.startsWith("a"));
		System.out.println(anyStartsWithA);

		boolean allStartsWithA = stringCollection.stream().allMatch(
				str -> str.startsWith("a"));
		System.out.println(allStartsWithA);

		boolean noneStartsWithZ = stringCollection.stream().noneMatch(
				str -> str.startsWith("z"));
		System.out.println(noneStartsWithZ);

		Optional<String> reduced = stringCollection.stream().sorted()
				.reduce((str1, str2) -> str1 + "#" + str2);
		reduced.ifPresent(System.out::println);
	}

}
